# coding:utf8
"""

"""

import poplib
import base64
from email.parser import Parser
from email.header import decode_header
from email.utils import parseaddr
# Local
from e_mail.send.m_iniRead import format_file as ff

mailQQ = '../send/_sup/info_126Email.ini'


def get_email_str():
    _info = ff(mailQQ)
    ser = poplib.POP3('pop.126.com')  # 创建pop实例
    ser.user(_info['mailUser'])  # 登录 user
    ser.pass_(_info['mailPasswd'])  # 登录 密码

    rsp, msg_list, rsp_siz = ser.list()  # 邮件列表
    print(f'{rsp}\t|{msg_list}\t|{rsp_siz}')
    print(f'{type(rsp)}\t|{type(msg_list)}\t|{type(rsp_siz)}\t')

    total_mail_numbers = len(msg_list)  # 下面单纯获取最新的一封邮件
    rsp, msgLines, msgSize = ser.retr(len(msg_list))
    print(f'{rsp}\t|{msgLines}\t|{msgSize}')
    print(f'{type(rsp)}\t|{type(msgLines)}\t|{type(msgSize)}\t')
    msg = b'\r\n'.join(msgLines).decode('gb18030')
    print(msg)


if __name__ == '__main__':
    get_email_str()